from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadData
from django.conf import settings



def openid_signature(openid):
    serializer = Serializer(settings.SECRET_KEY,600)
    data = {'openid':openid}
    openid_byte = serializer.dumps(data)
    return openid_byte.decode()

def check_openid(openid):
    serializer = Serializer(settings.SECRET_KEY,600)
    openid_data = serializer.loads(openid)
    try:
        openid = openid_data.get('openid')
    except BadData:
        return None
    else:
        return openid
